package com.atguigu.gulimall.product.controller;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.product.entity.BrandEntity;
import com.atguigu.gulimall.product.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * TEST
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-05-11 21:24:11
 */

@RestController
@RequestMapping("product/brand")
public class TestController {


    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @RequestMapping("/listTest")
    //@RequiresPermissions("product:brand:list")
    public R list() {
        List<BrandEntity> list = brandService.list();
        return R.ok().put("List", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/infos/{brandId}")
    //@RequiresPermissions("product:brand:info")
    public R info(@PathVariable("brandId") Long brandId) {
        BrandEntity brand = brandService.getById(brandId);

        return R.ok().put("brand", brand);
    }

    /**
     * 测试保存功能
     */
    @RequestMapping("/saveTest")
    public R saveTest(){
        BrandEntity brandEntity = new BrandEntity();
        brandEntity.setName("小米");
        brandEntity.setDescript("雷猴王的公司");
        brandService.save(brandEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/updateTest")
    //@RequiresPermissions("product:brand:update")
    public R update() {
        BrandEntity brandEntity = brandService.getById(1);
        brandEntity.setName("小米2");
        brandEntity.setDescript("雷猴王的公司2");
        brandService.updateById(brandEntity);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/deleteTest")
    //@RequiresPermissions("product:brand:delete")
    public R delete() {
        brandService.removeById(1);
        return R.ok();
    }

}

